/*
 * @: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-09-17 14:24:11
 * @LastEditors: ziwei
 * @LastEditTime: 2021-11-02 15:45:43
 */
// 管道  信息交流的通道 类似：events on emit
function createChannel() {
    let currentTakers = [];//listeners
    function on(actionType,taker) {//take
        take.actionType = actionType;
        currentTakers.push(taker);
    }
    function emit(action) {//put
        currentTakers.forEach(taker=>{
            if(taker.actionType = action.type){
                take(action)
            }
        })
    }
    return {on,emit}
}

function createStore() {
    let listeners =[];
    function on(type,listener) {
        listener.type = type;
        listener.push(listener);
    }
    function emit(action) {
        listeners.forEach(listener=>{
            if(listener.type===action.type){
                listener(action)
            }
        })
    }
    return  {on,emit}
}

export default createChannel;

//redux dispatch(action) 全局的listeners都要执行